﻿using Styx.WoWInternals;
using Styx.Common;

namespace KingWoW
{
    public static class Keybinds
    {
        // Sounds from http://www2.research.att.com/~ttsweb/tts/demo.php

        internal static void Pulse()
        {
            // KeybindPauseRotation \\
            if (IsKeyDown(ExtraUtilsSettings.Instance.PauseButton))
            {
                switch (ExtraUtilsSettings.Instance.PauseRotation)
                {
                    case true:
                        ExtraUtilsSettings.Instance.PauseRotation = !ExtraUtilsSettings.Instance.PauseRotation;
                        Logging.Write("Combat Routine started");
                        if (ExtraUtilsSettings.Instance.SoundsEnabled)
                        {
                            try
                            {
                                SoundManager.LoadSoundFilePath(@"\Routines\King-WoW\Sounds\CombatRoutineEnabled.wav");
                                SoundManager.SoundPlay();
                            }
                            catch { }
                        }
                        break;

                    case false:
                        ExtraUtilsSettings.Instance.PauseRotation = !ExtraUtilsSettings.Instance.PauseRotation;
                        Logging.Write("Combat Routine paused");
                        if (ExtraUtilsSettings.Instance.SoundsEnabled)
                        {
                            try
                            {
                                SoundManager.LoadSoundFilePath(@"\Routines\King-WoW\Sounds\CombatRoutinePaused.wav");
                                SoundManager.SoundPlay();
                            }
                            catch { }
                        }
                        break;

                    default:
                        return;
                }
            }

        }

        /// <summary>
        /// checks to see if the specified key has been pressed within wow.
        /// </summary>
        /// <param name="key">The key to check for (see Keyboardfunctions)</param>
        /// <returns>true if the player has pressed the key</returns>
        private static bool IsKeyDown(ExtraUtilsSettings.Keyboardfunctions key)
        {
            try
            {
                if (key == ExtraUtilsSettings.Keyboardfunctions.Nothing) return false;
                var raw = Lua.GetReturnValues("if " + key.ToString("g") + "() then return 1 else return 0 end");
                return raw[0] == "1";
            }
            catch
            {
                return false;
            }
        }
    }
}